/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Text,
    LineColumn,
    InputLine,
    TextArea,
    Input,
    Select,
    Button,
    useTheme,
    Table,
    TableBody,
    TableRow,
    CCell,
    Layer, TableHead, Cell, SuffixInput, BlobInputList, InputDatalist, CheckSwitch,
} from "customize-easy-ui-component";
import {
    InspectRecordLayout, InternalItemProps, SelectHookfork, useItemInputControl,
} from "../common/base";
import {useMeasureInpFilter} from "../common/hooks";
import {arraySetInp, calcAverageArrObj, objNestSet} from "../../common/tool";
import {items漏磁检} from "../park/editor";

interface Props  extends InternalItemProps{
    label?: string;
    titles?: any[];
}
//第三个字段标识：是否出现：非首次定期检验。 其中'改资料'有特别的：
export const item资料审查o=[['设资料','设计资料',true],['安资料','安装资料',true],['改资料','改造或者重大修理资料',true],
                ['使资料','使用管理资料',false],['检资料','检验、检查资料',false],];
export const itemA资料审查: string[]=[];
item资料审查o.forEach(([name,title,initIsp], i:number)=>{
    itemA资料审查.push(name as string);
});
/**资料审查主体
 * */
export const MaterialReview=
React.forwardRef((
    { children, show ,alone=true,redId,nestMd,label,titles}:Props,  ref
) => {
    const [getInpFilter]=useMeasureInpFilter(null,itemA资料审查,);
    const {inp, setInp} = useItemInputControl({ ref });
    return <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                                nestMd={nestMd} alone={alone} label={label!}>
        <Text variant="h5">{label}：</Text>
        合计5个审查项目：
        <hr/>
        { item资料审查o.map(([name,title,initIsp]: any, i:number) => {
            return  <React.Fragment key={i}>
                项目{i+1} {'>'} {title}：
                <LineColumn key={i}>
                    {'改资料'===name && <InputLine key={i} label={'无此项'}>
                        <CheckSwitch checked={ !(inp?.[name]) }
                                     onChange={e => setInp({...inp, [name]: inp?.[name] ? undefined : {} })}/>
                        </InputLine>
                    }
                    {('改资料'!==name || inp?.[name]) && <>
                        <InputLine  label='审查结果' >
                            <Select inputSize="md" css={{minWidth:'140px',fontSize:'1.3rem',padding:'0 1rem'}}
                                    value={ inp?.[name]?.q  ||''} onChange={e => objNestSet(name,'q', e.currentTarget.value||undefined,inp,setInp) }>
                                <option></option>
                                <option>齐全</option>
                                <option>缺失</option>
                                <option>无资料</option>
                            </Select>
                        </InputLine>
                        { initIsp  &&
                            <InputLine  label={'非首次定期检验'}>
                                <CheckSwitch checked={inp?.[name]?.s || false}
                                             onChange={e => objNestSet(name,'s', inp?.[name].s ? undefined : true,inp,setInp)}/>
                            </InputLine>
                        }
                        <InputLine  label={'缺失情况'}>
                            <BlobInputList  value={inp?.[name]?.l ||''}
                                            onListChange={v => objNestSet(name,'l', v||undefined,inp,setInp) } />
                        </InputLine>
                    </>
                    }
                </LineColumn>
            </React.Fragment>;
        }) }
    </InspectRecordLayout>;
});

export const itemA上次问题: string[]=['上次报告','上次评级','上次缺处'];
export const PreviousQuestion=
    React.forwardRef((
        { children, show ,alone=true,redId,nestMd,label,titles}:Props,  ref
    ) => {
        const [getInpFilter]=useMeasureInpFilter(null,itemA上次问题,);
        const {inp, setInp} = useItemInputControl({ ref });
        return <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                                    nestMd={nestMd} alone={alone} label={label!}>
            <Text variant="h5">{label}：</Text>
            资料审查-资料审查情况
            <InputLine  label={'上次定期检验报告编号'}>
                <BlobInputList  value={inp?.上次报告 ||''}
                                onListChange={v => setInp({ ...inp, 上次报告: v||undefined}) } />
            </InputLine>
            <InputLine  label='上次定期检验安全状况等级评为' >
                <SuffixInput  value={inp?.上次评级 ||''}
                              onChange={e=>setInp({ ...inp, 上次评级: e.currentTarget.value||undefined})}>级。</SuffixInput>
            </InputLine>
            上次定期检验问题记载（注明上次定期检验发现的主要缺陷及处理情况）：
            <TextArea  value={inp?.上次缺处 ||''} rows={13}
                       onChange={e => setInp({ ...inp, 上次缺处: e.currentTarget.value||undefined}) } />
        </InspectRecordLayout>;
    });

